package org.example.controller;
import lombok.val;
import org.example.entity.ResultsInfoEntity;
import org.example.service.IndScoAnalyseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/results")
public class IndScoAnalyseController {

    @Autowired
    private IndScoAnalyseService indScoAnalyseService;

    /**
     * 获取某个学生的总成绩
     * @param studentId 学生ID
     * @return 总成绩
     */
    @GetMapping("/total/{studentId}")
    public Float getTotalScoreByStudent(@PathVariable long studentId) {
        return indScoAnalyseService.getTotalScoreByStudent(studentId);
    }

    /**
     * 获取某个考试的平均成绩
     * @param examId 考试ID
     * @return 平均成绩
     */
    @GetMapping("/average/{examId}")
    public Float getAverageScoreByExam(@PathVariable long examId) {
        return indScoAnalyseService.getAverageScoreByExam(examId);
    }

    /**
     * 获取某个考试的最高成绩
     * @param examId 考试ID
     * @return 最高成绩
     */
    @GetMapping("/highest/{examId}")
    public Float getHighestScoreByExam(@PathVariable long examId) {
        return indScoAnalyseService.getHighestScoreByExam(examId);
    }

    /**
     * 获取某个考试的通过人数
     * @param examId 考试ID
     * @param passingScore 及格分数
     * @return 通过人数
     */
    @GetMapping("/pass-count/{examId}")
    public int getPassCountByExam(@PathVariable long examId, @RequestParam Float passingScore) {
        return indScoAnalyseService.getPassCountByExam(examId, passingScore);
    }
    /**
     * 获取某个考试所有学生的成绩
     * @param examId 考试ID
     * @return 学生成绩列表
     */
    @GetMapping("/scores/{examId}")
    public List<ResultsInfoEntity> getStudentScoresByExam(@PathVariable long examId) {
        return indScoAnalyseService.getStudentScoresByExam(examId);
    }

    /**
     * 分析某个学生的答题情况
     * @param studentId 学生ID
     * @param examId 考试ID
     * @return 分析结果（正确答案与错误答案数）
     */
    @GetMapping("/analyze/{studentId}/{examId}")
    public Map<String, Integer> analyzeStudentAnswers(@PathVariable long studentId, @PathVariable long examId) {
        return indScoAnalyseService.analyzeStudentAnswers(studentId, examId);
    }
}

